package com.atguigu.spzx.manager.controller;

import com.atguigu.spyx.model.common.Result;
import com.atguigu.spyx.model.common.com.atguigu.spyx.model.entity.product.ProductSpec;
import com.atguigu.spzx.manager.service.ProductSpecService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @create 2023-11-09-15:45
 */
@RestController
@RequestMapping("/admin/product/spec")
public class ProductSpecController {

    @Resource
    ProductSpecService productSpecService;

    @GetMapping("/page/{pageNum}/{pageSize}")
    public Result page(@PathVariable Integer pageNum,
                       @PathVariable Integer pageSize){
        PageInfo<ProductSpec> pageInfo = productSpecService.page(pageNum,pageSize);
        return Result.ok().data(pageInfo);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        productSpecService.deleteById(id);
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id){
       ProductSpec productSpec = productSpecService.getById(id);
       return Result.ok().data(productSpec);

    }

    @PutMapping("/updateById")
    public Result updateById(@RequestBody ProductSpec productSpec){
        productSpecService.updateById(productSpec);
        return Result.ok();
    }
    @PostMapping("/save")
    public Result save(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.ok();
    }

    @GetMapping("/findAll")
    public Result findAll(){
        List<ProductSpec> list = productSpecService.findAll();
        return Result.ok().data(list);
    }





}
